home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / mint / lib / mntlib44.zoo / mntlib / div.c < prev    next >
C/C++ Source or Header  |  1994-03-01  |  786b  |  48 lines

  1. /*
  2.  * div
  3.  *    this one should be compat with -fpcc-struct-return
  4.  *
  5.  *    ++jrb    bammi@dsrgsun.ces.cwru.edu
  6.  */
  7. #include <stdlib.h>
  8.  
  9. #ifdef __GNUC__
  10.  
  11. long __divsi3(long, long);    /* returns: quot in d0.l  remainder in d1.l */
  12.  
  13. #ifdef __MSHORT__
  14. div_t
  15. div(int num, int denom)
  16. {
  17.     div_t     result;
  18.  
  19.     __asm__ volatile("\
  20.         divs    %4,%3    | %3/%2 must be a data reggie
  21.         movw    %2,%0    | %2<31:16> == rem    %2<15:0> == quot
  22.         swap    %2
  23.         movw    %2,%1"
  24.         : "=g"(result.quot), "=g"(result.rem), "=d"((long)num)
  25.         : "2"((long)num), "d"(denom)
  26.         );
  27.  
  28.     return result;
  29. }
  30. #else /* !__MSHORT__ */
  31. __asm__(".stabs \"_div\",5,0,0,_ldiv");
  32. #endif
  33. #else /* !__GNUC__ */
  34.  
  35. div_t
  36. div(num, denom)
  37. int num, denom;
  38. {
  39.     div_t res;
  40.     
  41.     res.quot = num / denom;
  42.     res.rem = num % denom;
  43.     
  44.     return res;
  45. }
  46.  
  47. #endif /* !__GNUC__ */
  48.